import React from 'react'
import logo from '../../logo.svg'
import { Input,Cell,hooks,Button } from 'react-vant'
import { useAppDispatch } from '../../app/hooks'
import { functionAddAxiosList } from '../../app/lists'
import {useNavigate} from 'react-router-dom'
const Login: React.FC = () => {
  const dispatch=useAppDispatch()
  const navigate=useNavigate()
  const [state, updateState] = hooks.useSetState({
    title: '',
    id: Math.random().toString().slice(2),
    name: '',
    url: logo,
    isFinite:false,
    children:[],
  })
  const addClick=()=>{
    // 16.正确实现发布功能12:12
    dispatch(functionAddAxiosList(state))
    navigate('/home')
  }
  return (
    <div className='add'>
      <Cell>
        <Input
          value={state.title}
          onChange={title => updateState({ title })}
          placeholder='姓名'
        />
      </Cell>
      <Cell>
        <Input
          value={state.name}
          onChange={name => updateState({ name })}
          placeholder='话语'
        />
      </Cell>
      <Button type='primary' onClick={()=>addClick()}>发布</Button>
    </div>
  )
}

export default Login